#include "mainwindow.h"
#include <ukui-log4qt.h>

#include <QTranslator>
#include <QDir>
#include <QDebug>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    initUkuiLog4qt("kylin-theme-builder");
    //防止多开
    QSharedMemory fixsharedmemory("kylin-theme-builder");
    if (fixsharedmemory.attach())
    {
        fixsharedmemory.detach();
    }
    static QSharedMemory *singleApp = new QSharedMemory("kylin-theme-builder");
    if(!singleApp->create(1))//创建失败
    {
        qApp->quit();
        return -1;
    }
    //翻译
    QTranslator app_trans;
    QString locale = QLocale::system().name();
    QString trans_path;
    if (QDir("/usr/share/kylin-theme-builder/translations").exists()) {
        trans_path = "/usr/share/kylin-theme-builder/translations";
    } else {
        trans_path = qApp->applicationDirPath() + "/translations";
    }
    if (!app_trans.load("themebuilder_" + locale + ".qm", trans_path)) {
        qDebug() << "Load translation file："
                 << "themebuilder_" + locale + ".qm from" << trans_path << "failed!";
    } else {
        a.installTranslator(&app_trans);
    }
//    QTranslator translator;
//    translator.load("translation/themebuilder_zh_CN.qm");
//    qApp->installTranslator(&translator);
    MainWindow w;
    w.show();
    return a.exec();
}
